package com.fireline.beauty.seting;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import com.fireline.beauty.jdbc.SqliteJdbcImpl;
import com.zgw.fireline.base.controls.DataTable;
import com.zgw.fireline.base.controls.DataTableColumn;
import com.zgw.fireline.base.dataset.Dataset;

/**
 * 套装组合产品添加
 * */
public class TzzhcpDlg extends Dialog {
	private Text text;
	private Text textSl;
	/**
	 * @wbp.nonvisual location=17,552
	 */
	public final Dataset dataset = new Dataset(
			"\r\nselect cpbh,cpmc,lb,tm,jj from cpxx \r\nwhere ? is null\r\nor like('%'||?||'%',cpmc)  \r\nor like('%'||?||'%',cpbh) \r\nor like('%'||?||'%',tm) \r\nor like('%'||?||'%',jm) \r\n",
			SqliteJdbcImpl.INSTANCE);
	public int sl;

	/**
	 * Create the dialog.
	 * 
	 * @param parentShell
	 */
	public TzzhcpDlg(Shell parentShell) {
		super(parentShell);
		setShellStyle(SWT.MAX);
	}

	/**
	 * Create contents of the dialog.
	 * 
	 * @param parent
	 */
	@Override
	protected Control createDialogArea(Composite parent) {
		getShell().setText("添加套装组合产品");
		Composite container = (Composite) super.createDialogArea(parent);
		GridLayout gl_container = new GridLayout(1, false);
		gl_container.marginWidth = 0;
		container.setLayout(gl_container);
		{
			Composite composite = new Composite(container, SWT.NONE);
			composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
					false, 1, 1));
			GridLayout gl_composite = new GridLayout(6, false);
			gl_composite.horizontalSpacing = 0;
			gl_composite.marginTop = 20;
			gl_composite.marginWidth = 20;
			composite.setLayout(gl_composite);
			{
				Label lblNewLabel = new Label(composite, SWT.NONE);
				lblNewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER,
						false, false, 1, 1));
				lblNewLabel.setText("请输入产品名称：");
			}
			{
				text = new Text(composite, SWT.BORDER);
				text.addModifyListener(new ModifyListener() {

					@Override
					public void modifyText(ModifyEvent e) {
						doSearch();
					}
				});

				text.setMessage("在些输入名称、编号、简码、条码");
				{
					GridData gd_text = new GridData(SWT.FILL, SWT.CENTER, true,
							false, 1, 1);
					gd_text.widthHint = 150;
					text.setLayoutData(gd_text);
				}
			}
			{
				Label lblNewLabel_1 = new Label(composite, SWT.NONE);
				{
					GridData gd_lblNewLabel_1 = new GridData(SWT.RIGHT,
							SWT.CENTER, false, false, 1, 1);
					gd_lblNewLabel_1.horizontalIndent = 20;
					lblNewLabel_1.setLayoutData(gd_lblNewLabel_1);
				}
				lblNewLabel_1.setText("数量：");
			}
			{
				textSl = new Text(composite, SWT.BORDER);
				textSl.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
						false, 1, 1));
			}
			{
				Button btnNewButton = new Button(composite, SWT.NONE);
				{
					GridData gd_btnNewButton = new GridData(SWT.LEFT,
							SWT.CENTER, false, false, 1, 1);
					gd_btnNewButton.horizontalIndent = 10;
					gd_btnNewButton.widthHint = 60;
					btnNewButton.setLayoutData(gd_btnNewButton);
				}
				btnNewButton.setText("确定");
				btnNewButton.addSelectionListener(new SelectionAdapter() {
					@Override
					public void widgetSelected(SelectionEvent e) {
						okPressed();
					}
				});
			}
			{
				Button btnNewButton_1 = new Button(composite, SWT.NONE);
				{
					GridData gd_btnNewButton_1 = new GridData(SWT.LEFT,
							SWT.CENTER, false, false, 1, 1);
					gd_btnNewButton_1.horizontalIndent = 10;
					gd_btnNewButton_1.widthHint = 60;
					btnNewButton_1.setLayoutData(gd_btnNewButton_1);
				}
				btnNewButton_1.setText("退出");
			}
		}
		{
			DataTable dataTable = new DataTable(container, SWT.BORDER
					| SWT.FULL_SELECTION, dataset);
			dataTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
					true, 1, 1));
			dataTable.setHeaderVisible(true);
			dataTable.setLinesVisible(true);
			{
				DataTableColumn dtblclmnCpbh = new DataTableColumn(dataTable,
						SWT.NONE, "cpbh");
				dtblclmnCpbh.setText("产品编号");
				dtblclmnCpbh.setWidth(100);
			}
			{
				DataTableColumn dtblclmnCpmc = new DataTableColumn(dataTable,
						SWT.NONE, "cpmc");
				dtblclmnCpmc.setText("产品名称");
				dtblclmnCpmc.setWidth(150);
			}
			{
				DataTableColumn dtblclmnLb = new DataTableColumn(dataTable,
						SWT.NONE, "lb");
				dtblclmnLb.setText("类别");
				dtblclmnLb.setWidth(100);
			}
			{
				DataTableColumn dtblclmnTm = new DataTableColumn(dataTable,
						SWT.NONE, "tm");
				dtblclmnTm.setText("条码");
				dtblclmnTm.setWidth(120);
			}
		}
		dataset.setKeyColumns(new String[] {});
		setParams();
		doSearch();
		return container;
	}

	protected void doSearch() {
		setParams();
		dataset.update();
	}

	/**
	 * Create contents of the button bar.
	 * 
	 * @param parent
	 */
	@Override
	protected void createButtonsForButtonBar(Composite parent) {

	}

	@Override
	protected void okPressed() {
		if (dataset.getSelectedIndex() != -1) {
			sl = Integer.parseInt(textSl.getText());
			super.okPressed();
		}
	}

	/**
	 * Return the initial size of the dialog.
	 */
	@Override
	protected Point getInitialSize() {
		return new Point(596, 421);
	}

	protected void setParams() {
		dataset.setParam(0,text.getText());
		dataset.setParam(1,text.getText());
		dataset.setParam(2,text.getText());
		dataset.setParam(3,text.getText());
		dataset.setParam(4,text.getText());
	}

	public static void main(String[] args) {
		TzzhcpDlg dlg = new TzzhcpDlg(new Shell());
		dlg.open();
	}
}
